//
//  YKVL0MainViewController.m
//  DoorBell
//
//  Created by 王兴海 on 2021/5/28.
//  Copyright © 2021 王兴海. All rights reserved.
//

#import "YKVL0MainViewController.h"
#import "VL0View.h"
#import "VL5CallVideoVController.h"
#import "VL4CallVideoVController.h"
#import "LockSettingViewController.h"
@interface YKVL0MainViewController ()
/*锁占位按钮*/
@property (nonatomic, strong)UIImageView *lockStateImageview;
@property (nonatomic, strong)UILabel *stateLabel;
@property (nonatomic, strong)UIButton *openLock;
@property (nonatomic, strong)VL0View *lock_message_view;
@property (nonatomic, strong)VL0View *lock_alarm_view;
@property (nonatomic, strong)VL0View *ring_message_view;
@property (nonatomic,strong) dispatch_source_t dis_timer;
@property (nonatomic,assign)__block int timeout;
@end

@implementation YKVL0MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [HexChangeRGB colorWithHexString:@"#FBF8F3"];
     FBDevicesList *list  = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"bid"),bg_sqlValue(self.bid),bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken])]] firstObject];
     if (list.status) {
        self.lockStateImageview.image = [UIImage imageNamed:@"vl0_door_open"];
     }else{
        self.lockStateImageview.image = [UIImage imageNamed:@"index_vl0_eco_mode"];
     }
     
     self.stateLabel.text = @"实时视频";
     self.lock_message_view.backgroundColor = [UIColor whiteColor];
     self.lock_alarm_view.backgroundColor = [UIColor whiteColor];
     self.ring_message_view.backgroundColor = [UIColor whiteColor];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:OPEN_SMART_LOCK_RESULT object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(open_smart_lock_result:) name:OPEN_SMART_LOCK_RESULT object:nil];
    

    [[NSNotificationCenter defaultCenter] removeObserver:self name:OPEN_SMART_LOCK_RESPONSE object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(open_smart_lock_response:) name:OPEN_SMART_LOCK_RESPONSE object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:DEVST object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(devst:) name:DEVST object:nil];
    
}

- (void)devst:(NSNotification*)nitifacation
{
    NSDictionary *dict =  [nitifacation object];
    if ([self.bid isEqualToString:[dict objectForKey:@"bid"]]) {
        [self reloadView];
    }

   
}

- (void)setBid:(NSString *)bid
{
     _bid = bid;
    
    [self reloadView];
}

- (void)reloadView
{
    FBDevicesList *list  = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"bid"),bg_sqlValue(self.bid),bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken])]] firstObject];
     self.view.backgroundColor = [HexChangeRGB colorWithHexString:@"#FBF8F3"];
    [self setup];
    
    if (list.status) {
        self.lockStateImageview.image = [UIImage imageNamed:@"vl0_door_open"];
        self.stateLabel.text = @"实时视频";
        self.refresh = NO;
    }else{
        
        if (self.refresh) {
            self.lockStateImageview.image = [UIImage imageNamed:@"index_vl0_eco_mode"];
            self.stateLabel.text = @"省电运行中";
            self.refresh = NO;
        }else{
            if (_dis_timer) {
                dispatch_source_cancel(_dis_timer);
                _dis_timer = nil;
            }
            
            
            if (list.work_mode == 0) {
                
                if (!list.status) {
                    self.lockStateImageview.image = [UIImage imageNamed:@"index_vl0_eco_mode"];
                    self.stateLabel.text = @"省电运行中";
                }
            }else{
                
                _timeout = 3; // 倒计时时间
                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                _dis_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
                dispatch_source_set_timer(_dis_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
                dispatch_source_set_event_handler(_dis_timer, ^{
                    _timeout--;
                    if (_timeout <= 0) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            if (!list.status) {
                                self.lockStateImageview.image = [UIImage imageNamed:@"index_vl0_eco_mode"];
                                self.stateLabel.text = @"省电运行中";
                            }
                            if(_dis_timer){
                                dispatch_source_cancel(_dis_timer);
                                _dis_timer = nil;
                            }
                        });
                    }
                });
                dispatch_resume(_dis_timer);
                
            }
        }
    }

     self.lock_message_view.backgroundColor = [UIColor whiteColor];
     self.lock_alarm_view.backgroundColor = [UIColor whiteColor];
     self.ring_message_view.backgroundColor = [UIColor whiteColor];
}

-(void)open_smart_lock_result:(NSNotification*)notification
{
    NSDictionary *dict = (NSDictionary*)notification.object;
    switch ([[dict objectForKey:@"ret"] intValue]) {
        case 0:
        {
            [SVProgressHUD dismiss];
            [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"Unlocking successful", nil)];
        }
            break;
            
        case 1:
        {
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"开锁失败", nil)];
        
        }
            break;
            
        case 2:
        {
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"门已反锁", nil)];
            
        }
            break;
            
        case 3:
        {
           
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"密码已冻结", nil)];
            
        }
            break;
            
        default:
        {
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"开锁失败", nil)];
        }
            break;
    }
}


#pragma mark: E6开锁处理结果
- (void)open_smart_lock_response:(NSNotification*)notification
{
    NSLog(@"收到开锁指令");
    [SVProgressHUD showWithStatus:@"正在开锁中..."];
}


- (void)setup
{
     UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
     backbtn.frame = CGRectMake(0,0,40,80);
     backbtn.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentLeft;
    
    [backbtn setImage:[UIImage imageNamed:@"ic_menu_icon"] forState:UIControlStateNormal];
    [backbtn addTarget:self action:@selector(selectLeftActionClick) forControlEvents:UIControlEventTouchUpInside];
    [backbtn SG_imagePositionStyle:SGImagePositionStyleDefault spacing:5];
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbtn];
 
    UIButton *setBtn = [UIButton buttonWithType:UIButtonTypeCustom];
     setBtn.frame = CGRectMake(0,0,40,80);
     setBtn.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentRight;
    
    FBDevicesList *list  = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"bid"),bg_sqlValue(self.bid),bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken])]] firstObject];
    
    if (list.remoteupg == 1 || list.remoteupg == 2) {
        [setBtn setImage:[UIImage imageNamed:@"ic_menu_icon_new_update"] forState:UIControlStateNormal];
    }else{
         [setBtn setImage:[UIImage imageNamed:@"ic_menu_icon_new"] forState:UIControlStateNormal];
    }
    
    [setBtn addTarget:self action:@selector(settingBtnActionClick) forControlEvents:UIControlEventTouchUpInside];
    [setBtn SG_imagePositionStyle:SGImagePositionStyleDefault spacing:5];
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:setBtn];
    
    UILabel *titleLabel  = [[UILabel alloc]init];
     titleLabel.textColor = [HexChangeRGB colorWithHexString:@"#333333"];
     titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:20.0];
     titleLabel.text = list.nick;
     titleLabel.textAlignment = NSTextAlignmentCenter;
     titleLabel.frame = CGRectMake(0, 0, 80, 25);
     self.navigationItem.titleView = titleLabel;

}



- (void)settingBtnActionClick
{

     LockSettingViewController *vc =[[LockSettingViewController alloc]init];
     vc.bid = self.bid;
    [self.navigationController pushViewController:vc animated:YES];
    
}


- (void)selectLeftActionClick
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    //设置导航栏背景图片为一个空的image，这样就透明了
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    //去掉透明后导航栏下边的黑线
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
    [UIApplication sharedApplication].statusBarStyle =  UIStatusBarStyleDefault;
    
    FBDevicesList *list  = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"bid"),bg_sqlValue(self.bid),bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken])]] firstObject];
    
   
        [AFNHTTPSRequest httpsRequestWithUrl:[YKBusinessFramework get_shadow_settings:self.bid lastUpdate:0] errorHint:^(id errorData) {
            
            NSLog(@"get_shadow_settings  errorData-->%@ ",errorData);
        } result:^(id data) {

            NSLog(@"get_shadow_settings  data-->%@ ",data);
            if ([[data objectForKey:@"code"] intValue] == 0){
                
                NSDictionary *settingDict = [data objectForKey:@"settings"];
                
                FBDevicesList *devicesList = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"bid"),bg_sqlValue(self.bid),bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken])]] firstObject];
          
                if (devicesList) {
                    if ([settingDict objectForKey:@"lcd_timeout"]) {
                        devicesList.lcd_timeout = [[settingDict objectForKey:@"lcd_timeout"] intValue];
                    }
                    if ([settingDict objectForKey:@"work_mode"]) {
                        devicesList.work_mode = [[settingDict objectForKey:@"work_mode"] intValue];
                    }
                    
                    if ([settingDict objectForKey:@"alive_start_time"]) {
                        devicesList.alive_start_time = [settingDict objectForKey:@"alive_start_time"];
                    }
                
                    if ([settingDict objectForKey:@"alive_stop_time"]) {
                        devicesList.alive_stop_time = [settingDict objectForKey:@"alive_stop_time"];
                    }
                    
                    if ([settingDict objectForKey:@"video_time"]) {
                        list.video_time = [[settingDict objectForKey:@"video_time"] intValue];
                    }
                    if ([settingDict objectForKey:@"alm_mod"]) {
                        list.alm_mod = [[settingDict objectForKey:@"alm_mod"] intValue];
                    }
                    
                    if ([devicesList bg_saveOrUpdate]) {
                        NSLog(@"锁信息更新成功");
                    }
                }
            }
        }];
            
        [AFNHTTPSRequest httpsRequestWithUrl:[YKBusinessFramework get_shadow_state:self.bid] errorHint:^(id StaterrorData) {
            NSLog(@"获取状态失败-->%@",StaterrorData);
        } result:^(id StateData) {
            NSLog(@"获取状态 -- >%@",StateData);

            if ([[StateData objectForKey:@"code"] intValue] == 0){
                NSDictionary *stateDict = [StateData objectForKey:@"state"];
                
                FBDevicesList *stateInfo = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken]),bg_sqlKey(@"bid"),bg_sqlValue(self.bid)]] firstObject];
               
                if (stateInfo) {
                    stateInfo.wifi_ssid = [stateDict objectForKey:@"wifi_ssid"];
                    stateInfo.wifi_rssi = [stateDict objectForKey:@"wifi_level"];
                    stateInfo.vnum = [stateDict objectForKey:@"vnum"];
                    stateInfo.camera_id = [[stateDict objectForKey:@"camera_id"] intValue];
                    stateInfo.flexible_unlock = [[stateDict objectForKey:@"flexible_unlock"] intValue];
                    stateInfo.videocall_height = [[stateDict objectForKey:@"videocall_height"] intValue];
                    stateInfo.videocall_width = [[stateDict objectForKey:@"videocall_width"] intValue];
                    stateInfo.dual_camera = [[stateDict objectForKey:@"dual_camera"] intValue];
                    stateInfo.netType = [[stateDict objectForKey:@"netType"] intValue];
                    
                    
                    
                    if ([stateInfo bg_saveOrUpdate]) {
                        NSLog(@"锁信息更新成功");
                    }
                }
            }
        }];
        
    [AFNHTTPSRequest httpsRequestWithUrl:[YKBusinessFramework eques_get_vl0_psd:self.bid] errorHint:^(id errorData) {
        [SVProgressHUD dismiss];
    } result:^(id data) {
        if ([[data objectForKey:@"code"] intValue] == 0) {
             NSDictionary *dict =  [data objectForKey:@"data"];
             BOOL status =  [[dict objectForKey:@"state"] boolValue];
             FBDevicesList *list = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken]),bg_sqlKey(@"bid"),bg_sqlValue(self.bid)]] firstObject];
             list.sercurityStatus = status;
             list.sercurityCode =  [NSString stringWithFormat:@"%@",[dict objectForKey:@"pwd"]];
            [list bg_saveOrUpdate];
        }
    }];

    
    
}


- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    if (_dis_timer) {
        dispatch_source_cancel(_dis_timer);
        _dis_timer = nil;
    }
    // 如果不想让其他页面的导航栏变为透明 需要重置
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}


- (UIImageView*)lockStateImageview
{
    if (!_lockStateImageview) {
         _lockStateImageview = [[UIImageView alloc]init];
         _lockStateImageview.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(makecall)];
        [_lockStateImageview addGestureRecognizer:tap];
        [self.view addSubview:_lockStateImageview];
        [_lockStateImageview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view.mas_centerX);
            make.top.equalTo(self.view.mas_top).offset([UIDevice dev_navigationFullHeight] + 80);
            make.height.width.mas_offset(200);
        }];
    }
    return _lockStateImageview;
}


- (UILabel*)stateLabel
{
    if (!_stateLabel) {
         _stateLabel = [[UILabel alloc]init];
         _stateLabel.numberOfLines = 0;
         _stateLabel.textAlignment = NSTextAlignmentLeft;
         _stateLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18.0];
        [self.view addSubview:_stateLabel];
        [_stateLabel sizeToFit];
        [_stateLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.lockStateImageview.mas_bottom).offset(14);
            make.centerX.equalTo(self.view.mas_centerX);
        }];
    }
    return _stateLabel;
}

- (void)makecall
{

    if ([self.lockStateImageview.image isEqual:[UIImage imageNamed:@"index_vl0_eco_mode"]]) {
        [SVProgressHUD showErrorWithStatus:@"省电运行中！"];
        return;
    }
    
    FBDevicesList *list  = [[FBDevicesList bg_find:@"FBDevicesList" where:[NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"bid"),bg_sqlValue(self.bid),bg_sqlKey(@"userName"),bg_sqlValue([Tooles getuserToken])]] firstObject];
    
    if (list.role == EQUESVL4 || list.role == EQUESVM2CP) {
        
        VL4CallVideoVController *vc = [[VL4CallVideoVController alloc]init];
        vc.bid = self.bid;
        vc.is_invite = YES;
        vc.OnePresent = YES;
        if (!vc.navigationController.visibleViewController)
        {
             vc.modalPresentationStyle =  UIModalPresentationFullScreen;
            [self.view.window.rootViewController presentViewController:vc animated:YES completion:^{

            }];
        }
        
    }else{
        
        VL5CallVideoVController *vc = [[VL5CallVideoVController alloc]init];
        vc.bid = self.bid;
        vc.is_invite = YES;
        vc.OnePresent = YES;
        if (!vc.navigationController.visibleViewController)
        {
             vc.modalPresentationStyle =  UIModalPresentationFullScreen;
            [self.view.window.rootViewController presentViewController:vc animated:YES completion:^{

            }];
        }

    }
    
    
}


- (void)clickSmartButton:(UIButton*)sender
{
    

}


- (VL0View*)lock_message_view
{
    if (!_lock_message_view) {
         _lock_message_view = [[VL0View  alloc]initWithIcon:@"vlo_lock_battery" title:@"锁消息" batteryTitle:@"" battery:70];
         _lock_message_view.userInteractionEnabled = YES;
        [self.view addSubview:_lock_message_view];
        [_lock_message_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(14);
            make.right.equalTo(self.view.mas_right).offset(-14);
            make.top.equalTo(self.lockStateImageview.mas_bottom).offset(90);
            make.height.mas_offset(60);
        }];
        _lock_message_view.layer.cornerRadius= 8 ;
        _lock_message_view.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lock_message_view_click)];
        [_lock_message_view addGestureRecognizer:tap];
    }
    return _lock_message_view;
}

- (void)lock_message_view_click
{
    
    /*获取服务器上存在的锁消息的天数*/
    [AFNHTTPSRequest httpsRequestWithUrl:[YKBusinessFramework getLockRecordCountWithLockid:self.bid] errorHint:^(id  _Nonnull errorData) {
        NSLog(@"errorData -- %@",errorData);
    } result:^(id  _Nonnull data) {
        NSLog(@"data -- %@",data);
    }];
    

    
    
    /*
     
     获取具体某个时间的开锁消息
     
     + (NSURL*)getLockRecordWithLockid:(NSString*)lockID startTime:(long long)startTime end_time:(long long)end_time offset:(int)offset limit:(int)limit;
     
     
     开锁消息中的 type
     -1 无效值
     0 密码开锁;
     1 密码开锁;
     2 指纹开锁;
     3 卡片开锁;
     4 钥匙开锁;
     5 遥控开锁;
     6 一键开启（门内按键开门）;
     7 APP开锁;
     8 胁迫开锁（在指纹开锁内）;
     9 猫眼开锁（上位机开锁）;
     10 人脸开锁;
     11 掌纹用户;
     12 虹膜用户;
     13 临时用户;
     14指静脉开锁;
     15掌静脉开锁;
     16默认用户开锁;
     17声纹开锁;
     18蓝牙钥匙开锁;
     19室内把手开锁
     20组合开锁
     21机械开锁
     22虚位密码开锁
     */
    
    
   
}



- (VL0View*)lock_alarm_view
{
    if (!_lock_alarm_view) {
        _lock_alarm_view = [[VL0View  alloc]initWithIcon:@"vlo_lock_battery" title:@"锁告警消息" batteryTitle:@"" battery:70];
        _lock_alarm_view.userInteractionEnabled = YES;
        [self.view addSubview:_lock_alarm_view];
        [_lock_alarm_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(14);
            make.right.equalTo(self.view.mas_right).offset(-14);
            make.top.equalTo(self.lock_message_view.mas_bottom).offset(30);
            make.height.mas_offset(60);
        }];
        _lock_alarm_view.layer.cornerRadius = 8 ;
        _lock_alarm_view.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lock_alarm_view_click)];
        [_lock_alarm_view addGestureRecognizer:tap];
    }
    return _lock_alarm_view;
}

- (void)lock_alarm_view_click
{
    [AFNHTTPSRequest httpsRequestWithUrl:[YKBusinessFramework getSmartLockAlarmCountWithLockid:self.bid] errorHint:^(id  _Nonnull errorData) {
        NSLog(@"errorData -- %@",errorData);
    } result:^(id  _Nonnull data) {
        NSLog(@"data -- %@",data);
    }];
    
    /*
     锁告警中的 alarm
     -1 无效值
     1错误报警（输入错误密码或指纹或刷卡超过 10 次就报警）;
     2胁迫报警（输入劫持指纹或密码开锁报警）（如果产生开锁信息，将与门锁状态信息一同发出，不发这条指令）;
     3防撬报警（锁被撬开）;
     4钥匙尝试开锁被冻结（使用机械钥匙开锁）（如果产生开锁信息，将与门锁状态信息一同发出，不发这条指令）;
     5低电量报警（电池电量不足）（如果产生开锁信息，将与门锁状态信息一同发出）;
     6不能正常出锁舌 6 次;
     7门铃报警（暂时不用）;
     8门没关好;
     9锁状态检测错误报警;
     10开锁异常报警;
     11关锁异常报警;
     12指纹尝试开锁被冻结;
     13卡片尝试开锁被冻结;
     14系统锁定报警;
     15遥控尝试开锁被冻结;
     16密码尝试开锁被冻结;
     17人脸尝试开锁被冻结;
     18密码尝试开锁报警;
     19遥控尝试开锁报警;
     20卡片尝试开锁报警;
     21指纹尝试开锁报警;
     22钥匙尝试开锁报警;
     23人脸尝试开锁报警;
     24强行开门;
     25掌纹尝试开锁报警;
     26陌生人逗留报警;
     27门口有陌生人;
     28门口有人徘徊;
     29保留;
     30忘拔钥匙;
     31锁门提醒;
     32门已解锁;
     33任意开锁被冻结;
     34敲门提醒;
     35SOS求救提醒;
     36门已反锁;
     37常开已开启;
     38添加用户;
     39删除用户;
     40用户初始化;
     41删除全部用户;
     42火灾报警;
     43非活体人脸;
     44被人尾随;
     45特斯拉开锁报警;
     46指静脉尝试开锁被冻结
     47指静脉尝试开锁报警
     48掌静脉尝试开锁被冻结
     49掌静脉尝试开锁报警
     50哨兵报警
     51被人劫持
     52设备异常报警
     53掌纹尝试开锁被冻结
     54虹膜尝试开锁被冻结
     55虹膜尝试开锁报警
     56高温报警
     57烟雾报警
     58窗磁报警
     59万能钥匙开锁提醒
     60燃气泄漏报警
     61布防报警
     62定时上锁提醒
     63主动查看提醒
     64门内按键开锁
     65门内把手开锁
     66门内按键关锁
     67门内把手关锁
     68常开已取消
     69锁芯盖已打开
     70锁芯盖已关闭
     71消毒灯已打开
     72消毒灯已关闭
     73门孔未对准
     74门过紧
     75紧急开锁
     */
   
}


- (VL0View*)ring_message_view
{
    if (!_ring_message_view) {
         _ring_message_view = [[VL0View alloc]initWithIcon:@"vl0_doorbell_battery" title:@"门铃消息" batteryTitle:@"" battery:70];
        [self.view addSubview:_ring_message_view];
        [_ring_message_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(14);
            make.right.equalTo(self.view.mas_right).offset(-14);
            make.top.equalTo(self.lock_alarm_view.mas_bottom).offset(30);
            make.height.mas_offset(60);
        }];
         _ring_message_view.layer.cornerRadius = 8 ;
         _ring_message_view.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ring_message_view_click)];
        [_ring_message_view addGestureRecognizer:tap];
    }
    return _ring_message_view;
}

- (void)ring_message_view_click
{
    [AFNHTTPSRequest httpsRequestWithUrl:[YKBusinessFramework equesGetRingCountUrlWithBid:self.bid] errorHint:^(id  _Nonnull errorData) {
        NSLog(@"errorData -- %@",errorData);
    } result:^(id  _Nonnull data) {
        NSLog(@"data -- %@",data);
    }];
}




@end
